<?php include_once('header.php'); ?>

<?php include_once('left_navigation.php'); ?>

<?php
include('../classess/class_affiliate_user.php');

$affUser = new affUser();

$affiliate_id = $_SESSION['id'];


$banks_details = $affUser->get_details($affiliate_id);

$affiliate_username  = $_SESSION['user_name'];

?>

<div class="col-lg-12"><!-- Start Middle Content Div-->

    <div class="box">

        <div class="row">	

			<div class="col-lg-12" style="margin-top:-20px; text-align:center;">
                <div class="box" style="font-size:16px;">
					Your Refrence URL is 
					<a href="<?php echo ReferenceLink; ?>" target="_blank" style="text-decoration:none; color:blue; "><?php echo ReferenceLink; ?></a>	
                </div>
                          <div class="box" style="font-size:16px;">                             
                              You get commission if someone make purchase of any ebook/training.  Sent him email about course or create a custom url with your ref link in which they interested.

                          </div>
            </div>

            <div class="col-lg-12">

                <div class="box">

                    <div class="box-header" data-original-title>

                        <h2><i class="fa fa-user"></i><span class="break"></span>Affiliate Name: <?php echo $affiliate_username;?></h2>

                        <div class="box-icon">

                            <a href="table.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>

                            <a href="table.html#" class="btn-close"><i class="fa fa-times"></i></a>

                        </div>

                    </div>

                    <div class="box-content">

                        <?php
                        if (isset($delete_activate_user)) {
                            ?>

                            <div class="alert alert-info">

                                <div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>

                                <div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $delete_activate_user; ?></div>

                                <div style="clear:both;"></div>							

                            </div>

                            <?php
                        }
                        ?>

                        <div class="search_box">

                            <div class="fl_left sel_label_search">Search:</div>

                            <div class="fl_left" style="width:60%;">									

                                <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?home=1&user_id=<?php echo $_GET['user_id'];?>" id="search_form" name="search_form">

                                    <input type="text" name="search_value" id="search_value" placeholder="Search" value="<?php
                                    if (isset($_POST['search_value'])) {
                                        echo $_POST['search_value'];
                                    } else {
                                        echo '';
                                    } if (isset($_GET['srch_value'])) {
                                        echo $_GET['srch_value'];
                                    } else {
                                        echo '';
                                    }
                                    ?>">&nbsp;

                                    <input type="submit" name="submit_search" id="submit_search" class="btn btn-blue srch_btn" value="Search">

                                </form>



                            </div>

                            <div class="clear_fix"></div>

                        </div>

                        <table class="table table-striped table-bordered">

                            <thead>

                                <tr>

                                    <th>S.No.</th>
                                    <th>User Name</th>
                                   
                                    <th>Course Name</th>
                                    <th>Course Price</th>
                                    <th>Commission Percentage</th>

                                    <th>commission</th>

                                    <th>Date of Purchase</th>
									<th>Is Refund</th>

                                </tr>

                            </thead>   

                            <tbody>

                                <?php
                                $rec_limit = 25;



                                $condition_search = '';

                                $value = '';

                                if (isset($_POST['search_value'])) {

                                    $value = trim($_POST['search_value']);



                                    if (!empty($value)) {

                                        $cond_where = ' AND';

                                        $condition_search = $cond_where . " (cour.course_name like '%" . $value . "%')";
                                    }
                                }



                                if (isset($_GET['srch_value'])) {

                                    $value = $_GET['srch_value'];



                                    if (!empty($value)) {

                                        $cond_where = ' AND';



                                        $condition_search = $cond_where . " (cour.course_name like '%" . $value . "%' )";
                                    }
                                }



                                $select_count_course = "SELECT count(com.id) FROM tbl_commission as com  
                                JOIN tbl_user as user  ON com.trainee_id = user.id          
                                JOIN tbl_courses as cour  ON com.course_id = cour.id
                                WHERE trainee_id= '" . $_GET['user_id'] . "'
                                    " . $condition_search;
                                $result_count_course = mysql_query($select_count_course);
                                $row = mysql_fetch_array($result_count_course);
                                $rec_count = $row[0];
                                if (isset($_GET['page'])) {

                                    $page = $_GET['page'] + 1;

                                    $offset = $rec_limit * $page;
                                } else {

                                    $page = 0;

                                    $offset = 0;
                                }

                                $serial_number = $page * $rec_limit;
                                $left_rec = $rec_count - ($page * $rec_limit);
                               $total_user_amt = " SELECT SUM(c.`commission`) AS total_commission 
 FROM tbl_commission AS c
JOIN tbl_user_details AS ud ON c.`trainee_detail_id` = ud.`id` 
WHERE  c.trainee_id= '" . $_GET['user_id'] . "' AND ud.`is_refund` = '0'  ";
                                 $data_total_Amount = mysql_fetch_assoc(mysql_query($total_user_amt));
                                 
                                $select_trainer = "SELECT *,user.create_ts as user_create_date,detail.course_fee as user_course_fee FROM tbl_commission as com  
                                                    JOIN tbl_user as user  ON com.trainee_id = user.id  
                                                    LEFT JOIN tbl_ebook as ebook  ON com.course_id = ebook.id 			
                                                    LEFT JOIN tbl_courses as cour  ON com.course_id = cour.id 
                                                    JOIN tbl_user_details as detail  ON com.trainee_detail_id = detail.id 
                                WHERE com.trainee_id= '" . $_GET['user_id'] . "'
                                " . $condition_search . "GROUP BY com.id ORDER BY com.id DESC LIMIT " . $offset . ", " . $rec_limit;
                                
								
								$query_trainer = mysql_query($select_trainer) or die(mysql_error());
                                $i = 1;
                                $total_amount = '';
                               if (mysql_num_rows($query_trainer) > 0) {
                                    while ($row = mysql_fetch_array($query_trainer)) {
                                        $serial_number++;
                                        if($row['is_ebook'] == 1){
                                            $course_name = $row['ebook_name'];
                                            $course_fee = $row['user_course_fee'];
                                        }else{
                                            $course_name = $row['course_name'];
                                            $course_fee = $row['user_course_fee'];
                                        }
                                        if ($row['is_refund']) {
                                            
                                        }else{
                                            //$total_amount += $row['commission'];
                                        }
                                        echo '
					<tr>
                                        <td>' . $serial_number . '</td>
<td>' . $row['username'] . '</td>                                        
<td>' . $course_name . '</td>
                                        <td>' . $course_fee . '</td>';
        				if ($row['is_refund']) {
                                          echo 	'<td> - </td>
					<td> - </td>
        				<td>';
                                      }   else{
                                          echo 	'<td>' . $row['commission_percentage'] . '</td>
					<td>' . $row['commission'] . '</td>
        				<td>';
                                      }
                                        echo date('d F Y',strtotime($row['user_create_date']));
                                        //$dateValue = explode(" ", $dateValue);
                                        /*$time = strtotime($dateValue[0]);
                                        $month = date("F", $time);
                                        $year = date("Y", $time);
                                        $day = date("d", $time);
                                        echo $day . ' ' . $month . ' ' . $year;
                                        */echo '</td>
										<td>';
                                        if ($row['is_refund']) {
                                            echo '<span class="label label-success">Yes</span>';
                                        } else {
                                            echo '<span class="label label-default">No</span>';
                                        }
                                        echo '</td>
				</tr>
					';
                                        $i++;
                                    }
                                } else {
                                    echo '<tr>
                                            <td colspan="9" style="text-align:center;">No Records Found</td>
        				</tr>';
                                }
                                ?>						
                            </tbody>
                        </table> 
                        
                        <b>Total Amount:</b> $ <?php echo $data_total_Amount['total_commission']; ?>
                        <?php
                        echo '<ul class="pagination">';
                        if ($rec_count > $rec_limit) {
                            if ($page > 0 && $left_rec > $rec_limit) {
                                $last = $page - 2;
                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?home=1&user_id=' . $_GET['user_id'] . '&page=' . $last . '&srch_value=' . $value . '" class="anc_click">Prev</a></li> ';
                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?home=1&user_id=' . $_GET['user_id'] . '&page=' . $page . '&srch_value=' . $value . '" class="anc_click">Next</a></li>';
                            } else if ($page == 0) {
                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?home=1&user_id=' . $_GET['user_id'] . '&page=' . $page . '&srch_value=' . $value . '" class="anc_click">Next</a></li>';
                            } else if ($left_rec < $rec_limit || $left_rec == $rec_limit) {
                                $last = $page - 2;
                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?home=1&user_id=' . $_GET['user_id'] . '&page=' . $last . '&srch_value=' . $value . '" class="anc_click">Prev</a></li>';
                            }
                        }
                        echo '</ul>';
                        ?>
                    </div>
                </div>
            </div><!--/col-->
        </div><!--/row-->
<?php /* ?>
        <div class="row">		

            <div class="col-lg-12">

                <div class="box">

                    <div class="box-header" data-original-title>

                        <h2><i class="fa fa-user"></i><span class="break"></span>Bank Detail</h2>

                        <div class="box-icon">

                            <a href="table.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>

                            <a href="table.html#" class="btn-close"><i class="fa fa-times"></i></a>

                        </div>

                    </div>

                    <div class="box-content">

                        
                        <div class="search_box">

   <!--                         <div class="fl_left sel_label_search">Search:</div>

                            <div class="fl_left" style="width:60%;">									

                                <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?aff_mn=1" id="search_form" name="search_form">

                                    <input type="text" name="search_value" id="search_value" placeholder="Search" value="<?php
                                    if (isset($_POST['search_value'])) {
                                        echo $_POST['search_value'];
                                    } else {
                                        echo '';
                                    } if (isset($_GET['srch_value'])) {
                                        echo $_GET['srch_value'];
                                    } else {
                                        echo '';
                                    }
                                    ?>">&nbsp;

                                    <input type="submit" name="submit_search" id="submit_search" class="btn btn-blue srch_btn" value="Search">

                                </form>



                            </div>
-->
                            <div class="clear_fix"></div>

                        </div>

                        <table class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>S.No.</th>
                                    <th>Bank Name</th>
                                    <th>Account No.</th>
                                    <th>Transaction Id</th>
                                    <th>Total Amount</th>
                                    <th>Pending Amount</th>
                                    <th>Date</th>
                                    <th>Note</th>
                                </tr>

                            </thead>   

                            <tbody>

                                <?php
                                $rec_limits = 3;



                                $condition_search = '';

                                $value = '';
/*
                                if (isset($_POST['search_value'])) {
                                   $value = trim($_POST['search_value']);
                                    if (!empty($value)) {
                                        $cond_where = ' AND';
                                        $condition_search = $cond_where . " (b.username like '%" . $value . "%' OR b.email_id like '%" . $value . "%')";
                                    }
                                }
                                if (isset($_GET['srch_value'])) {
                                    $value = $_GET['srch_value'];
                                    if (!empty($value)) {
                                        $cond_where = ' AND';
                                        $condition_search = $cond_where . " (b.username like '%" . $value . "%' OR b.email_id like '%" . $value . "%')";
                                    }
                                }
*/
/*

                                $select_count_detail = "SELECT count(at_id) FROM tbl_aff_transfer WHERE at_affilate_id= '" . $_GET['user_id'] . "'" . $condition_search;

                                $result_count_detail = mysql_query($select_count_detail);



                                $row_detail = mysql_fetch_array($result_count_detail);

                                $rec_count_detail = $row_detail[0];



                                if (isset($_GET['pages'])) {

                                    $pages = $_GET['pages'] + 1;

                                    $offsets = $rec_limits * $pages;
                                } else {

                                    $pages = 0;

                                    $offsets = 0;
                                }
                                $serial_numbers = $pages * $rec_limits;
                                $left_recs = $rec_count - ($pages * $rec_limits);
                                $select_bank = "SELECT * FROM tbl_aff_transfer WHERE at_affilate_id= '" . $_GET['user_id'] . "'" . $condition_search . " ORDER BY at_id DESC LIMIT " . $offset . ", " . $rec_limit;
                                $query_bank = mysql_query($select_bank) or die(mysql_error());

                                $i = 1;

                                if (mysql_num_rows($query_bank) > 0) {

                                    while ($rows = mysql_fetch_array($query_bank)) {

                                        $serial_numbers++;

                                        echo '
						<tr><td>'.$serial_numbers.'</td>
						<td>' . $rows['bank_name'] . '</td>
						<td>' . $rows['account_number'] . '</td>
        					<td>' . $rows['transaction_id'] . '</td>
						<td>' . $rows['total_amount'] . '</td>
						<td>' . $rows['pending_amount'] . '</td>
						<td>' . $rows['at_date'] . '</td>
                                                <td>' . $rows['at_note'] . '</td>';
                                                echo '
        						</tr>

										';

                                        $i++;
                                    }
                                } else {

                                    echo '<tr>

										<td colspan="9" style="text-align:center;">No Records Found</td>

									</tr>';
                                }
                                ?>						

                            </tbody>

                        </table>  

                        <?php
                        echo '<ul class="pagination">';

                        if ($rec_count > $rec_limit) {

                            if ($page > 0 && $left_rec > $rec_limit) {

                                $last = $page - 2;

                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $last . '&srch_value=' . $value . '" class="anc_click">Prev</a></li> ';

                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $page . '&srch_value=' . $value . '" class="anc_click">Next</a></li>';
                            } else if ($page == 0) {

                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $page . '&srch_value=' . $value . '" class="anc_click">Next</a></li>';
                            } else if ($left_rec < $rec_limit || $left_rec == $rec_limit) {

                                $last = $page - 2;

                                echo '<li><a href="' . $_SERVER["PHP_SELF"] . '?aff_mn=1&page=' . $last . '&srch_value=' . $value . '" class="anc_click">Prev</a></li>';
                            }
                        }

                        echo '</ul>';
                        ?>

                    </div>

                </div>

            </div><!--/col-->



        </div><!--/row-->
<?php */?>



    </div><!-- End Box Div-->

</div><!-- End Middle Content Div-->

<?php include_once('footer.php'); ?>

<script>

    $ = jQuery.noConflict();

    $(document).ready(function() {

        $('.chk_sub_chkbox').live('click', function() {

            var payer_id = $(this).next().next('input#userdtlpayerId').val();

            if ($('#sel_pay_type' + payer_id + ':checked').length != 0) {

                if ($('#pay_type_status' + payer_id).val() == '') {

                    alert('Plaese Select One payment Method');

                    $('#sel_pay_type' + payer_id + '').trigger('click');

                }

                else {

                    var user_dtl_pyr_id = payer_id;

                    var status_pay_type = $('#pay_type_status' + user_dtl_pyr_id).val();

                    $.ajax({
                        type: 'POST',
                        data: {pay_type_status: status_pay_type, userdtlpayerId: user_dtl_pyr_id},
                        dataType: 'json',
                        url: '../classess/user_paid_type.php',
                        success:
                                function(j)

                                {

                                    console.log(j);

                                    $('form#paidStatusForm' + user_dtl_pyr_id).parent('td').html(j);

                                }

                    });

                }

            }

        });



        $('.close').click(function() {

            $('.alert-info').addClass('hide');

        });



        $('#count_val').keyup(function() {

            var val = $('#count_val').val();

            var j_user_id = $('#user_id_val').val();

            var j_user_dtl_id = $('#user_dtl_id_val').val();

            if (val > 0) {

                $.ajax({
                    type: 'POST',
                    data: {field_value: val, pst_user_id: j_user_id, pst_user_dtl_id: j_user_dtl_id},
                    dataType: 'json',
                    url: '../classess/ebook_download_time.php',
                    success:
                            function(j)

                            {

                                $('#count_val').val(val);

                            }

                });

            }

        });

    });





</script>